#ifndef istream_h__
#define istream_h__
#include "util/assert.h"

namespace gecko
{

	// Interface for streams.
	class IStream
	{
	public:
		enum eMode
		{
			ModeRead,
			ModeWrite,
		};

		enum eSeekPos
		{
			SeekSet,
			SeekCur,
			SeekEnd,
		};

		// Templated function to serialise typed data.
		template<typename T> size_t Serialise(T& data);

		// Serialise some bytes.
		size_t Serialise(char* buffer, size_t len);

		// Serialise a string (length is stored before the string).
		size_t SerialiseString(char* str);

		// Get the stream mode (Read/Write).
		eMode GetMode();

		// Seek to a new position in the stream.
		virtual bool Seek(size_t offset, eSeekPos origin) = 0;

		// Get the position of the read/write.
		virtual size_t GetPosition() = 0;

	protected:
		// pure virtual to do the actual serialise operation.
		virtual size_t SerialiseBuffer(char* buffer, size_t len) = 0;

		// store the mode
		eMode m_mode;
	};

	template<typename T>
	size_t IStream::Serialise(T& data)
	{
		return SerialiseBuffer((char*)&data, sizeof(T));
	}

}

#endif
